home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Tools / Packer / xad / Developer / Sources / tools / xadUnDisk.c < prev    next >
C/C++ Source or Header  |  1999-11-06  |  8KB  |  284 lines

  1. #define NAME         "xadUnDisk"
  2. #define DISTRIBUTION "(Freeware) "
  3. #define REVISION     "0"
  4.  
  5. /* Programmheader
  6.  
  7.     Name:        xadUnDisk
  8.     Author:        SDI
  9.     Distribution:    Freeware
  10.     Description:    dearchives disk archives
  11.     Compileropts:    -
  12.     Linkeropts:    -gsi -l amiga
  13.  
  14.  1.0   18.11.98 : first version
  15. */
  16.  
  17. #include <proto/xadmaster.h>
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20. #include <exec/memory.h>
  21. #include <dos/dosasl.h>
  22. #include <utility/hooks.h>
  23. #include "SDI_defines.h"
  24. #include "SDI_compiler.h"
  25. #define SDI_TO_ANSI
  26. #include "SDI_ASM_STD_protos.h"
  27.  
  28. #ifdef __SASC
  29.   #define xadmasterbase     xadMasterBase 
  30.   #define ASSIGN_XAD
  31. #else
  32.   struct xadMasterBase * xadMasterBase = 0;
  33.   #define ASSIGN_XAD     xadMasterBase = xadmasterbase;
  34. #endif
  35. struct DosLibrary *     DOSBase = 0;
  36. struct ExecBase *     SysBase  = 0;
  37.  
  38. #define PARAM    "FROM/A,TO,LOWCYL/N,HIGHCYL/N,ENTRY/N,PASSWORD,"    \
  39.         "NE=NOEXTERN/S,INFO=LIST/S,SHOWTEXTS/S,OW=OVERWRITE/S,"    \
  40.         "IG=IGNOREGEOMETRY/S"
  41.  
  42. struct Args {
  43.   STRPTR from;
  44.   STRPTR to;
  45.   LONG * lowcyl;
  46.   LONG * highcyl;
  47.   LONG * entry;
  48.   STRPTR password;
  49.   ULONG  noextern;
  50.   ULONG  info;
  51.   ULONG  showtexts;
  52.   ULONG  overwrite;
  53.   ULONG  ignoregeometry;
  54. };
  55.  
  56. ASM(ULONG) SAVEDS progrhook(REG(a0, struct Hook *),
  57.   REG(a1, struct xadProgressInfo *));
  58. struct Hook prhook = {{0,0},(ULONG (*)()) progrhook, 0, 0};
  59.  
  60. ULONG start(void)
  61. {
  62.   ULONG ret = RETURN_FAIL;
  63.   struct DosLibrary *dosbase;
  64.  
  65.   SysBase = (*((struct ExecBase **) 4));
  66.   { /* test for WB and reply startup-message */
  67.     struct Process *task;
  68.     if(!(task = (struct Process *) FindTask(0))->pr_CLI)
  69.     {
  70.       WaitPort(&task->pr_MsgPort);
  71.       Forbid();
  72.       ReplyMsg(GetMsg(&task->pr_MsgPort));
  73.       return RETURN_FAIL;
  74.     }
  75.   }
  76.  
  77.   if((dosbase = (struct DosLibrary *) OpenLibrary("dos.library", 37)))
  78.   {
  79.     LONG err = 0;
  80.     struct xadMasterBase *xadmasterbase;
  81.  
  82.     DOSBase = dosbase;
  83.     if((xadmasterbase = (struct xadMasterBase *)
  84.     OpenLibrary("xadmaster.library", 1)))
  85.     {
  86.       LONG def = 1;
  87.       struct Args args;
  88.       struct RDArgs *rda;
  89.       
  90.       memset(&args, 0 , sizeof(struct Args));
  91.       args.entry = &def;
  92.  
  93.       ASSIGN_XAD
  94.       if((rda = ReadArgs(PARAM, (LONG *) &args, 0)))
  95.       {
  96.     if(args.to || args.info)
  97.     {
  98.       struct xadArchiveInfo *ai;
  99.     
  100.       if((ai = (struct xadArchiveInfo *)
  101.       xadAllocObjectA(XADOBJ_ARCHIVEINFO, 0)))
  102.       {
  103.         if(!(err = xadGetInfo(ai, XAD_INFILENAME, args.from,
  104.         XAD_NOEXTERN, args.noextern, args.password ? XAD_PASSWORD :
  105.         TAG_IGNORE, args.password, TAG_DONE)))
  106.         {
  107.           if(args.info)
  108.           {
  109.             struct xadDiskInfo *xdi;
  110.             Printf("ArchiverName:   %s\n", ai->xai_Client->xc_ArchiverName);
  111. #ifdef DEBUG
  112.             Printf("Password:       %s\n", ai->xai_Password ? ai->xai_Password : "<none>");
  113.             Printf("InSize:         %ld\n", ai->xai_InSize);
  114.             Printf("InPos:          %ld\n", ai->xai_InPos);
  115. #endif
  116.  
  117.             xdi = ai->xai_DiskInfo;
  118.             while(xdi)
  119.             {
  120.           if(xdi->xdi_EntryNumber != 1 || xdi->xdi_Next)
  121.                 Printf("\nEntry:          %ld\n", xdi->xdi_EntryNumber);
  122.               Printf("EntryInfo:      %s\n", xdi->xdi_EntryInfo ? xdi->xdi_EntryInfo : "<none>");
  123. #ifdef DEBUG
  124.               Printf("Flags:          ");
  125.               if(xdi->xdi_Flags & XADDIF_CRYPTED)
  126.                 Printf("XADDIF_CRYPTED ");
  127.               if(xdi->xdi_Flags & XADDIF_INFOTEXT)
  128.                 Printf("XADDIF_INFOTEXT ");
  129.               if(xdi->xdi_Flags & XADDIF_BANNER)
  130.                 Printf("XADDIF_BANNER ");
  131.               Printf(xdi->xdi_Flags ? "\n" : "<none>\n");
  132. #endif
  133.               Printf("SectorSize:     %ld\n", xdi->xdi_SectorSize);
  134.               Printf("Sectors:        %ld\n", xdi->xdi_TotalSectors);
  135.               Printf("Cylinders:      %ld\n", xdi->xdi_Cylinders);
  136.               Printf("CylSectors:     %ld\n", xdi->xdi_CylSectors);
  137.               Printf("Heads:          %ld\n", xdi->xdi_Heads);
  138.               Printf("TrackSectors:   %ld\n", xdi->xdi_TrackSectors);
  139.               Printf("LowCyl:         %ld\n", xdi->xdi_LowCyl);
  140.               Printf("HighCyl:        %ld\n", xdi->xdi_HighCyl);
  141.               if(xdi->xdi_Flags & XADDIF_INFOTEXT)
  142.                 Printf("There is an InfoText with size %ld.\n", xdi->xdi_InfoTextSize);
  143.               if(xdi->xdi_Flags & XADDIF_BANNER)
  144.                 Printf("There is a Banner with size %ld.\n", xdi->xdi_BannerSize);
  145.               if(xdi->xdi_Flags & XADDIF_CRYPTED)
  146.                 Printf("The entry is encrypted\n");
  147.               xdi = xdi->xdi_Next;
  148.             }
  149.             ret = 0;
  150.           }
  151.           else
  152.           {
  153.         struct xadDeviceInfo *dvi = 0;
  154.  
  155.             if(args.to[strlen(args.to)-1] == ':')
  156.             {
  157.               if((dvi = (struct xadDeviceInfo *)
  158.               xadAllocObjectA(XADOBJ_DEVICEINFO, 0)))
  159.               {
  160.                 args.to[strlen(args.to)-1] = 0; /* strip ':' */
  161.                 dvi->xdi_DOSName = args.to;
  162.               }
  163.               else
  164.                 err = XADERR_NOMEMORY;
  165.             }
  166.             if(args.showtexts)
  167.             {
  168.               struct xadDiskInfo *xdi = ai->xai_DiskInfo;
  169.  
  170.               while(xdi && xdi->xdi_EntryNumber < *args.entry)
  171.                 xdi = xdi->xdi_Next;
  172.               if(xdi)
  173.               {
  174.                 if(xdi->xdi_Flags & XADDIF_INFOTEXT)
  175.                   Printf("»»INFOTEXT««\n%s\n", xdi->xdi_InfoText);
  176.                     if(xdi->xdi_Flags & XADDIF_BANNER)
  177.                       Printf("»»BANNER««\n%s\n", xdi->xdi_Banner);
  178.               }
  179.             }
  180.             if(!err && !(err = xadDiskUnArc(ai, dvi ? XAD_OUTDEVICE :
  181.             XAD_OUTFILENAME, dvi ? (ULONG) dvi : (ULONG) args.to,
  182.             XAD_ENTRYNUMBER, *args.entry, args.lowcyl ?
  183.             XAD_LOWCYLINDER : TAG_IGNORE, args.lowcyl ? *args.lowcyl :
  184.             0, args.highcyl ? XAD_HIGHCYLINDER : TAG_IGNORE,
  185.             args.highcyl ? *args.highcyl : 0, XAD_OVERWRITE,
  186.             args.overwrite, XAD_IGNOREGEOMETRY, args.ignoregeometry,
  187.             XAD_PROGRESSHOOK, &prhook, TAG_DONE)))
  188.               ret = 0;
  189.             if(dvi)
  190.               xadFreeObjectA(dvi, 0);
  191.           }
  192.           xadFreeInfo(ai);
  193.         } /* xadGetInfo */
  194.  
  195.         xadFreeObjectA(ai, 0);
  196.           } /* xadAllocObject */
  197.         }
  198.         else
  199.           SetIoErr(ERROR_REQUIRED_ARG_MISSING);
  200.  
  201.         FreeArgs(rda);
  202.       } /* ReadArgs */
  203.  
  204.       if(CTRL_C)
  205.         SetIoErr(ERROR_BREAK);
  206.  
  207.       if(err)
  208.     Printf("An error occured: %s\n", xadGetErrorText(err));
  209.       else if(ret)
  210.         PrintFault(IoErr(), 0);
  211.  
  212.       CloseLibrary((struct Library *) xadmasterbase);
  213.     } /* OpenLibrary xadmaster */
  214.     else
  215.       Printf("Could not open xadmaster.library\n");
  216.     CloseLibrary((struct Library *) dosbase);
  217.   } /* OpenLibrary dos */
  218.   return ret;
  219. }
  220.  
  221. ASM(ULONG) SAVEDS progrhook(REG(a0, struct Hook *hook),
  222. REG(a1, struct xadProgressInfo *pi))
  223. {
  224.   ULONG ret = 0;
  225.  
  226.   switch(pi->xpi_Mode)
  227.   {
  228.   case XADPMODE_ASK:
  229.     {
  230.       UBYTE r;
  231.       if(pi->xpi_Status & XADPIF_OVERWRITE)
  232.       {
  233.         Printf("File already exists, overwrite? (Y|S|\033[1mN\033[0m): ");
  234.         Flush(Output());
  235.         SetMode(Input(), TRUE);
  236.         r = FGetC(Input());
  237.         if(r == 'Y' || r == 'y')
  238.           ret |= XADPIF_OVERWRITE;
  239.         else if(r == 'S' || r == 's')
  240.           ret |= XADPIF_SKIP;
  241.         SetMode(Input(), FALSE);
  242.       }
  243.       if(pi->xpi_Status & XADPIF_IGNOREGEOMETRY)
  244.       {
  245.         Printf("Drive geometry not correct, ignore? (Y|S|\033[1mN\033[0m): ");
  246.         Flush(Output());
  247.         SetMode(Input(), TRUE);
  248.         r = FGetC(Input());
  249.         if(r == 'Y' || r == 'y')
  250.           ret |= XADPIF_IGNOREGEOMETRY;
  251.         else if(r == 'S' || r == 's')
  252.           ret |= XADPIF_SKIP;
  253.         SetMode(Input(), FALSE);
  254.       }
  255.     }
  256.     break;
  257.   case XADPMODE_PROGRESS:
  258.     {
  259.       ULONG numcyl, fullsize, curcyl, i;
  260.  
  261.       i = pi->xpi_DiskInfo->xdi_CylSectors *
  262.           pi->xpi_DiskInfo->xdi_SectorSize;
  263.       numcyl = pi->xpi_HighCyl+1-pi->xpi_LowCyl;
  264.       fullsize = numcyl * i;
  265.       curcyl = pi->xpi_CurrentSize/i;
  266.  
  267.       Printf("\r\033[KWrote %ld of %ld bytes (%ld/%ld cylinders)",
  268.       pi->xpi_CurrentSize, fullsize, curcyl, numcyl);
  269.       Flush(Output());
  270.     }
  271.     break;
  272.   case XADPMODE_END: Printf("\r\033[KWrote %ld bytes (%ld cylinders)\n",
  273.     pi->xpi_CurrentSize, pi->xpi_HighCyl+1-pi->xpi_LowCyl);
  274.     break;
  275.   case XADPMODE_ERROR: Printf("\r\033[K");
  276.     break;
  277.   }
  278.  
  279.   if(!CTRL_C) /